﻿var grid, cbProgress;

//初始化表格
function InitGrid() {
    var BATCHNUMBER = $.trim($("#txtBATCHNUMBER").attr("value"));
    var CheckTimeS = $('#CheckTimeS').datebox('getValue');
    grid = $('#tab_list').datagrid({
        name: 'tbl_data',
        url: '/PickBatch/Query',
        title: '订单分拣批次列表',
        queryParams: {
            BATCHNUMBER: BATCHNUMBER,
            CheckTimeS: CheckTimeS
        },
        //width: 815,
        height: 650,
        //border : false,
        //fit: false,
        fitColumns: false,
        //nowrap: true,
        rownumbers: true,
        //showFooter: true,
        //loadMsg: '正在加载信息...',
        //frozen: true,
        //sortName: "CODE", //排序设置
        singleSelect: true,
        idField: 'BATCHNUMBER',
        columns: [[
        //{ field: 'ck', checkbox: true },
                    { field: 'BATCHNUMBER', title: '分拣批次号', align: 'center', sortable: true },
                    { field: 'BATCHDATE', title: '分拣日期', align: 'center', sortable: true },
                    { field: 'ORDERCOUNT', title: '订单数', align: 'center', sortable: true },
                    { field: 'PICKTASKCOUNT', title: '拣货订单数', align: 'center', sortable: true },
                    { field: 'FLAG', title: '状态', align: 'center', sortable: true, formatter: formatflag },
                    { field: 'CREATER', title: '操作', align: 'center', sortable: true, formatter: formataudit }
        ]],
        pagination: true,
        pageSize: 20,
        pageNumber: 1,
        pageList: [10, 20, 30, 40, 50],
        rownumbers: true, //行号
        onSortColumn: function (sort, order) {
            grid.datagrid('reload');
        }
    });
    //清空选择
    grid.datagrid('clearSelections');
}

function formatflag(val) {
    if (val != null) {
        if (val == 0) {
            return "未启用";
        }
        if (val == 1) {
            return "启用";
        }
    }
}

function Save(flag, batchnumber, batchdate) {
    $('#query').form('submit', {
        url: '/pickbatch/enable?batchnumber=' + batchnumber + '&batchdate=' + batchdate + '&flag=' + flag,
        success: function (data) {
            eval('data=' + data);
            if (data.success) {
                InitGrid();
            } else {
                $.messager.alert('错误', data.msg, 'error');
            }
        }
    })
}


function formataudit(val, row, index) {
    if (val != null) {
        var FLAG = row.FLAG;
        var batchnumber = row.BATCHNUMBER;
        var batchdate = row.BATCHDATE;
        if (FLAG == 0) {
            return "<a href='#' onclick='Save(\"1\"," + row.BATCHNUMBER + ",\"" + row.BATCHDATE + "\")'>启用</a>";
            
        }
        else {
            //return "<a href='/PickBatch/Enable?BATCHNUMBER=" + BATCHNUMBER + "&BATCHDATE=" + BATCHDATE + "&FLAG=0'>停用</a>";
            return "<a href='#' onclick='Save(\"0\"," + row.BATCHNUMBER + ",\"" + row.BATCHDATE + "\")'>停用</a>";
        }
    }
}